package com.codedancer.campus.client.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.client.service.ISchoolService;
import com.codedancer.campus.client.service.vo.school.SchoolVo;
import com.codedancer.campus.mapper.SchoolMapper;
import com.codedancer.campus.po.School;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class SchoolServiceImpl implements ISchoolService {

    @Autowired
    private SchoolMapper schoolMapper;


    /**
     * 获取全部学校(未删除和已启用)
     *
     * @return
     */
    @Override
    public List<SchoolVo> all() {
        List<School> schools = schoolMapper.allNoDeleteAndEnable();
        List<SchoolVo> schoolVos;
        schoolVos = schools.stream().map(school -> BeanUtil.copyProperties(school, SchoolVo.class))
            .collect(
                Collectors.toList());
        return schoolVos;
    }
}
